package com.example.my_2048.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.my_2048.R;
import com.example.my_2048.been.Game;
import com.example.my_2048.view.GameView;

/**
 * Created by tang on 16/8/18.
 */
public class Main extends Activity{
    private static Button btnReset;
    private static TextView tvCurrent,tvHistory;
    public static Main main;
    private static GameView gameView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        init();
    }

    private void init() {
        gameView= (GameView) findViewById(R.id.gamePanel);
        gameView.game=new Game();
        btnReset = (Button) findViewById(R.id.btnRestGame);
        tvCurrent = (TextView) findViewById(R.id.tvCurrenRusult);
        tvHistory = (TextView) findViewById(R.id.tvHistory);
        btnReset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

               resetGame();
            }
        });
        getHistoryScores();
        showCurrentScores();
    }

    public static void resetGame()
    {
        gameView.game.Reset();
        gameView.refreshPanel();
        showCurrentScores();
    }

    public Main() {
        main=this;
    }

    public static void showCurrentScores()
    {
        tvCurrent.setText(String.valueOf(gameView.game.getiSumScore()));
    }

    public static Main getMain() {
        return main;
    }

    public void getHistoryScores() {
        // TODO: 16/8/18 获得历史最高分
    }

}
